# 使用官方的 CentOS 镜像作为基础
FROM centos:latest

# 安装必要的依赖和工具
RUN yum -y update && \
    yum -y install epel-release && \
    yum -y install wget git gcc-c++ automake autoconf libtool make \
                   ncurses-devel zlib-devel libjpeg-devel openssl-devel \
                   e2fsprogs-devel sqlite-devel libuuid-devel \
                   unixODBC-devel libcurl-devel net-snmp-devel \
                   libtiff-devel libtermcap-devel ldns-devel \
                   gmp-devel libedit-devel speex-devel \
                   libmemcached-devel libyuv-devel \
                   libtheora-devel opus-devel libcodec2-devel \
                   libvpx-devel libvorbis-devel \
                   libsndfile-devel libtool-ltdl-devel \
                   libao-devel libresample-devel \
                   libcurl-devel lua-devel libidn-devel \
                   hiredis-devel libopus-devel portaudio-devel \
                   libtool-ltdl-devel libxml2-devel libxslt-devel \
                   libX11-devel libXt-devel libXdmcp-devel libXtst-devel \
                   zlib-devel alsa-lib-devel flite-devel libjpeg-turbo-devel \
                   gsm-devel libmemcached-devel libbson-devel libuv-devel \
                   jansson-devel libatomic_ops-devel mongodb-devel \
                   yasm nasm libwebsockets-devel jansson-devel \
                   libpcap-devel unixODBC-devel gnutls-devel \
                   postgresql-devel libsndfile-devel libjpeg-turbo-devel \
                   libpng-devel lua lua-devel lua-posix \
                   pkgconfig gcc-c++ bzip2 \
                   speex speex-devel \
                   bzip2-devel opus opus-devel \
                   silk silk-devel \
                   libvpx libvpx-devel \
                   libogg libogg-devel \
                   mpg123 mpg123-devel \
                   libtheora libtheora-devel \
                   libvorbis libvorbis-devel \
                   opencore-amr opencore-amr-devel \
                   flite flite-devel \
                   libsndfile libsndfile-devel \
                   libopus libopus-devel \
                   portaudio-devel \
                   libmemcached libmemcached-devel \
                   libcurl libcurl-devel \
                   opus opus-devel \
                   unixODBC unixODBC-devel \
                   libtool-ltdl libtool-ltdl-devel \
                   libtiff libtiff-devel \
                   libv4l libv4l-devel \
                   libva libva-devel \
                   opusfile opusfile-devel \
                   libxslt libxslt-devel \
                   libjpeg-turbo libjpeg-turbo-devel \
                   zlib zlib-devel \
                   xmlstarlet sox \
                   tftp-server flac \
                   pulseaudio-libs pulseaudio-libs-devel \
                   speexdsp speexdsp-devel \
                   java-1.8.0-openjdk-devel which && \
    yum clean all && \
    rm -rf /var/cache/yum

# 下载并编译 FreeSWITCH
RUN git clone -b v1.10 https://github.com/signalwire/freeswitch.git /usr/src/freeswitch \
    && cd /usr/src/freeswitch \
    && ./bootstrap.sh -j \
    && ./configure \
    && make \
    && make install \
    && make sounds-install \
    && make moh-install \
    && make cd-sounds-install \
    && make cd-moh-install \
    && cd /usr/src \
    && rm -rf /usr/src/freeswitch

# 暴露 FreeSWITCH 端口
EXPOSE 5060/tcp 5060/udp 5080/tcp 5080/udp 5066/tcp 5066/udp 8021/tcp 8022/tcp 7443/tcp 60535-65535/udp

# 启动 FreeSWITCH
CMD ["/usr/local/freeswitch/bin/freeswitch", "-nonat"]
